package com.qf.Controller;

import com.qf.entity.Emp;
import com.qf.service.EmpService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * --- 年少有为 ---
 *
 * @author ChenZhuo
 * @date 2025/8/8
 * @desc
 */
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;
    @GetMapping("/add")
    public R add(Emp emp){
        Boolean result =empService.add(emp);
        if ( result){
            return R.success();
        }else{
            return R.fail();
        }
    }
    @GetMapping("/delete")
    public R deleteById(int empno){
        Boolean result =empService.deleteById(empno);
        if ( result){
            return R.success();
        }else{
            return R.fail();
        }

    }
    @GetMapping("/update")
    public R update(Emp emp){

        Boolean result =empService.update(emp);

        if ( result){
            return R.success();
        }else{
            return R.fail();
        }

    }
    @GetMapping("/all/list")
    public R list(String empno){
        List<Emp> emps=null;
        Integer i=null;
        if(empno != null){
            i = Integer.parseInt(empno);
            emps = empService.list(i);
        }else{
            emps = empService.list();
        }
        if(emps != null){
            return R.success(emps);
        }else{
            return R.fail();
        }
    }
    @GetMapping("/list")
    public R listById(int empno){
        Emp emps = empService.listById(empno);
        if(emps != null){
            return R.success(emps);
        }else{
            return R.fail();
        }
    }


}
